package com.diors.game.engine.arpg.scene.model;

import java.util.List;

import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.diors.game.engine.arpg.npc.model.NpcBornModel;

/**
 * 场景Model
 * @author	darren.ouyang <ouyang.darren@gmail.com>
 * @date	2013-10-21
 * @version 1.0
 * @copyright Copyright (c) 2013, darren.ouyang
 */
@XmlRootElement(name = "scene")
@XmlAccessorType(XmlAccessType.FIELD)
public class SceneModel 
{
	
	/* 场景原型ID */
	@XmlAttribute(name = "id")
	private int id;
	
	/* 场景类型 */
	@XmlAttribute(name = "type")
	private int typeValue;
	private SceneTypeEnum type;
	
	@XmlAttribute(name = "height")
	private int height;
	
	@XmlAttribute(name = "width")
	private int width;
	
	/* 地图掩码 */
	@XmlElement(name="row")
	private List<SceneRowModel> rows;
	
	/* int[Y][X] */
	private int[][] code;
	
	private SceneLineModel lineModel;
	
	private List<NpcBornModel> bornModelList;
	
	void afterUnmarshal(Unmarshaller u, Object parent)
	{
		code = new int[rows.size()][rows.get(0).getCode().split(" ").length];
		int y, x;
		x = y = 0;
		for (SceneRowModel rowModel : rows)
		{
			String rowStr = rowModel.getCode();
			String[] rowArray = rowStr.split(" ");
			x = 0;
			for (String pointCode : rowArray)
			{
				code[y][x] = MapPoint.getIdByCode(pointCode);
				++x;
			}
			++y;
		}
		
		type = SceneTypeEnum.getType(typeValue);
	}
	
	
	
	public int getId() {
		return id;
	}
	public int getTypeValue() {
		return typeValue;
	}
	public SceneTypeEnum getType() {
		return type;
	}
	public List<SceneRowModel> getRows() {
		return rows;
	}
	public int[][] getCode() {
		return code;
	}

	public SceneLineModel getLineModel() {
		return lineModel;
	}

	public List<NpcBornModel> getBornModelList() {
		return bornModelList;
	}

	public void setLineModel(SceneLineModel lineModel) {
		this.lineModel = lineModel;
	}

	public void setBornModelList(List<NpcBornModel> bornModelList) {
		this.bornModelList = bornModelList;
	}

	
	
	
}
